package org.jeecg.modules.demo.evaluate.controller;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class SQLFileMerger {

    public static void mergeSQLFiles(String[] filePaths, String outputFilePath) {
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputFilePath))) {
            for (String filePath : filePaths) {
                try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
                    String line;
                    while ((line = reader.readLine()) != null) {
                        writer.write(line);
                        writer.newLine(); // 保持原始文件的换行格式
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        String folderPath = "C:\\Users\\29000\\Desktop\\能信\\物研\\wydb带结构\\wydb\\新建文件夹";    // 替换为文件夹的实际路径
        File folder = new File(folderPath);

        List<String> stringList = new ArrayList<>();

        if (folder.isDirectory()) {
            File[] files = folder.listFiles();
            for (File file : files) {
                if (file.isFile()) {
                    System.out.println(file.getName());
                    String filePath = "C:/Users/29000/Desktop/能信/物研/wydb带结构/wydb/新建文件夹/" + file.getName();
                    stringList.add(filePath);
                }
            }
        }


        String[] sqlFiles = stringList.toArray(new String[0]);
//                            {
//                            "C:/Users/29000/Desktop/能信/物研/wydb带结构/wydb/account2025-09-16 16-19-06.sql",
//                            "C:/Users/29000/Desktop/能信/物研/wydb带结构/wydb/app_version2025-09-16 16-19-06.sql"
//                            }; // 你的SQL文件路径数组
        String outputFile = "C:/Users/29000/Desktop/能信/物研/wydb带结构/wydb.sql"; // 输出文件路径
        mergeSQLFiles(sqlFiles, outputFile);
    }

}
